// pages/live/live.js
import { HTTP } from '../../utils/http.js'
let ajax = new HTTP()
const app = getApp()

Page({
    data: {
        page: 1,
        totalNum: 0,
        imgUrls: [],
        hotLive: [],
        placeType: 'live',
        zbactid: "",
        isEmpty: false
    },
    // 点击直播列表
    onLiveTap (event) {
        let id = event.detail.id
        let status = event.detail.status
        let zbactid = event.detail.zbactid
        console.log(zbactid)
        let name = event.detail.name
        let pic = event.detail.pic
        this.setData({
            zbactid: zbactid
        })
        this._getLive(status, id, name, pic)
    },
    // 点击banner
    onSwiperTap (event) {
        let id = event.detail.id
        let status = event.detail.status
        let name = event.detail.name
        let pic = event.detail.pic
        let zbactid = event.detail.zbactid
        this.setData({
            zbactid: zbactid
        })
        this._getLive(status, id, name, pic)
    },
    onLoad (options) {
        let memberid = wx.getStorageSync("memberid")
        wx.showLoading({
            title: '加载中',
        })
        this._getActiveList(memberid, this.data.page)
        this._getBannerList(memberid)
    },
    // 搜索
    onSearchTap () {
        wx.navigateTo({
            url: '/pages/search/search?id=' + this.data.placeType,
        })
    },
    // 下拉加载
    onReachBottom() {
        // 请求总分类
        if (this.data.page * 10 >= this.data.totalNum) {
            this.setData({
                isEmpty: true
            })
            return
        }
        wx.showLoading({
            title: '加载中',
        })
        this.data.page++
        this._getActiveList(app.globalData.memberid, this.data.page)
    },
    // 请求地址
    _getLive(status, id, name, pic) {
        if (status === 1) {
            // wx.showToast({
            //     title: '直播尚未开始，敬请期待！',
            //     icon: 'none'
            // })
            // wx.navigateTo({
            //     url: 'detail/detail?id=' + id,
            // })
            // wx.navigateTo({
            //     url: 'notice/notice?id=' + this.data.zbactid
            // })
            wx.navigateTo({
                url: 'detail/detail?id=' + id
            })
        }
        if (status === 2) {
            wx.navigateTo({
                url: 'detail/detail?id=' + id
            })
            // wx.navigateTo({
            //     url: 'detail/detail?scene=frommemberid_' + 111 + '-actid_' + id
            // })
        }
        // 重播
        if (status === 3) {
            wx.navigateTo({
                url: 'record/record?id=' + id + '&name=' + name + '&pic=' + pic
            })
        }
    },
    // 转发 
    onShareAppMessage: function () {

    },
    // 请求直播列表
    _getActiveList (memberid, page) {
        ajax.request({
            method: "GET",
            url: "activelist",
            data: {
                p: page,
                memberid: memberid
            },
            success: (res) => {
                wx.hideLoading()
                this.setData({
                    hotLive: this.data.hotLive.concat(res.data),
                    totalNum: res.total
                })
            }
        })
    },
    // 请求banner
    _getBannerList (memberid) {
        ajax.request({
            method: "GET",
            url: "activelist/banner",
            data: {
                memberid: memberid
            },
            success: (res) => {
                this.setData({
                    imgUrls: res.data
                })
            }
        })
    }
})